from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn.datasets import load_wine


wine = load_wine()
print(wine.data.shape)

from sklearn.model_selection import train_test_split, cross_val_score
Xtrain, Xtest, Ytrain, Ytest = train_test_split(wine.data,wine.target,test_size=0.3)

#实例化模型
clf = DecisionTreeClassifier(random_state=0)
rfc = RandomForestClassifier(random_state=0)

rfcs = cross_val_score(rfc,wine.data,wine.target,cv  = 10)
#训练
clf = clf.fit(Xtrain, Ytrain)
rfc = rfc.fit(Xtrain, Ytrain)

score_c = clf.score(Xtest, Ytest)
score_r = rfc.score(Xtest, Ytest)

print("Single Tree{}".format(score_c),"Random Forest{}".format(rfcs.mean()))
